#include <iostream>
using std::cout;
using std::endl;
using std::string;

class Person{
public:
    Person(string name,int age)
    : _name(name)
    , _age(age)
    {}

    void display() const{
        cout << "name:" << _name << endl
            << "age:" << _age << endl;
    }

private:
    string _name;
    int _age;
};

class Employee
: public Person
{
public:
    Employee(string name,int age,
             string department,double salary)
    : Person(name,age)
    , _department(department)
    , _salary(salary)
    {
        _totalSalary += _salary;    
        ++_totalNum;
    }

    void display() const{
        Person::display();
        cout << "department:" << _department << endl;
        cout << "salary:" << _salary << endl;
    }

    static double aveSalary(){
        return _totalSalary/_totalNum;
    }

    ~Employee(){
        _totalSalary -= _salary;
        --_totalNum;
    }
private:
    string _department;
    double _salary;
    static double _totalSalary;
    static int _totalNum;
};

double Employee::_totalSalary = 0;
int Employee::_totalNum = 0;

void test0(){
    Employee e1("a1",23,"sale",7000);
    Employee e2("a2",24,"HR",6000);
    Employee e3("a3",28,"ceo",30000);
    e1.display();
    cout << Employee::aveSalary() << endl;

}

int main(void){
    test0();
    return 0;
}

